﻿using Assets.Core.Common.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Nucleic.Core.DoMain;
using Nucleic.Core.Utils;
using Nucleic.Web.Dto.CheckItem;
using SqlSugar;

namespace Nucleic.Web.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CheckItemController : ControllerBase
    {
        /// <summary>
        /// 获取检验项目
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("GetAll")]
        public Result<List<CheckItemGetAllDto>> GetAll(string range)
        {

            //var item = SqlSugarFactory.Instance.Queryable<check_item>().First(x => x.item_id == "12435");
            //var d = item.price.ToString("##.##");
            var checkItem = SqlSugarFactory.Instance.Queryable<check_item>()
                 .InnerJoin<check_type>((t1, t2) => t1.item_id == t2.item_id)
                 .InnerJoin<time_range>((t1, t2, t3) => t2.type_id == t3.type_id)
                 //.LeftJoin<book_info>((t1, t2, t3) => t2.type_id == t3.range_id)
                 .Where((t1, t2, t3) => t1.status == "0" && t2.status == "0" && t3.status == "0" && t3.range == range)
                 .OrderBy((t1,t2,t3)=>t1.price).Select((t1, t2, t3) =>
                      new CheckItemGetAllDto
                      {
                          item_name = t1.name,
                          type_name = t2.name,
                          price = t1.price,
                          item_id = t1.item_id,
                          type_id = t2.type_id,
                          range_id = t3.range_id,
                          max_num = t3.max_num
                          //book_count= SqlFunc.Subqueryable<book_info>()
                          //.Where(s => s.range_id == range_id&&s.appo_date.Date==dateTime.Date&&(s.status=="0"||s.status=="1"||s.status=="2")).Count()
                      }).ToList();
            return Result<List<CheckItemGetAllDto>>.success(checkItem);
        }
    }
}
